<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>已知有字符串 foo=”get-element-by-id”,写一个 function 将其转化成驼峰 表示法”getElementById”</title>
</head>
<body>
  <script>
    function fn(res) {
      var arr = res.split('-')//  以“-”分隔符截取字符串，返回数组
      console.log(arr)
      for (var i = 1; i < arr.length; i++) {
        console.log(arr[i]);
        arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1)
      }
      res = arr.join("")
      return res
    }
    console.log(fn("get-element-by-id"))
  </script>
</body>
</html>